/***************************************************************************
 *   Copyleft 2006-2007 by												   *
 *	 Iwanicki Krzysztof													   *
 *   <gamma.mini.pw.edu.pl/~iwanickik>									   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 ***************************************************************************/
#include "./TriGregoryManager.h"
#include "../../resource.h"

/**************************************************************
* Constructors                                                *
***************************************************************/
TriGregoryManager::TriGregoryManager(Cursor3D* cursor, TriGregory* triGregory): Cursor3DManager(cursor) {
	mTriGregory = triGregory;
}
    
/**************************************************************
* Operators                                                   *
***************************************************************/
/*virtual*/ TriGregoryManager::~TriGregoryManager() {
	mTriGregory->SetMeshVisible(false);
	mTriGregory->SetPointsVisible(false);
}

/**************************************************************
* Other helpful functions                                     *
***************************************************************/
/*virtual*/ Object3D* TriGregoryManager::GetObject() {
	return mTriGregory;
}

/*virtual*/ cVoid TriGregoryManager::OnCommand(HWND hwnd, WPARAM wParam, LPARAM lParam, Engine3D* engine) {
	cUShort cmd = LOWORD(wParam);

	switch(cmd) {
		case ID_ACCEL_ENTER:
			break;
		default:
			OnChangeParams(cmd, engine);
	}
}

cVoid TriGregoryManager::OnChangeParams(cUShort cmd, Engine3D* engine) {
	switch(cmd) {
		case ID_CTRL_N:
			
			break;
		case ID_SHOWHIDEPOINTSCORDS:
			mTriGregory->SetMeshVisible(!mTriGregory->GetMeshVisible());
			break;
		case ID_ELLIPSOID_INCB:
			mTriGregory->SetPointsVisible(!mTriGregory->GetPointsVisible());
			break;
		case ID_ELLIPSOID_INCC:
			mTriGregory->ToggleContinuity();
			break;
		case ID_CTRL_J:
			mTriGregory->SetGregoryPrecision(mTriGregory->GetGregoryPrecision() + 1);
			break;
		case ID_ALT_J:
			mTriGregory->SetGregoryPrecision(mTriGregory->GetGregoryPrecision() -1);
			break;
		case ID_CTRL_K:
			mTriGregory->SetCurveParam(mTriGregory->GetCurveParam() + 1);
			break;
		case ID_ALT_K:
			mTriGregory->SetCurveParam(mTriGregory->GetCurveParam() - 1);
			break;
		default:
			OnTransform(cmd, engine);
			break;
	}
}

cVoid TriGregoryManager::OnTransform(cUShort cmd, Engine3D* engine) {
	switch(cmd) {
		case ID_ROTTXA:
			engine->mScene->Transform(Matrix4D::RotationX(-5.0f));
			break;
		case ID_ROTTXQ:
			engine->mScene->Transform(Matrix4D::RotationX(5.0f));
			break;
		case ID_ROTTYS:
			engine->mScene->Transform(Matrix4D::RotationY(-5.0f));
			break;
		case ID_ROTTYW:
			engine->mScene->Transform(Matrix4D::RotationY(5.0f));
			break;
		case ID_ROTTZD:
			engine->mScene->Transform(Matrix4D::RotationZ(-5.0f));
			break;
		case ID_ROTTZE:
			engine->mScene->Transform(Matrix4D::RotationZ(5.0f));
			break;
		case ID_TRANSIZ:
			engine->mScene->Transform(Matrix4D::Translation(Point4D(0.0f, 0.0f, 10.0f)));
			break;
		case ID_TRANSDZ:
			engine->mScene->Transform(Matrix4D::Translation(Point4D(0.0f, 0.0f, -10.0f)));
			break;
	}
}